<!-- 业务部-开发型体建档：蹇泽阳 -->
<template>
  <div class="app-container">
    <JFind
      :searchImg="false"
      :OriginalFilter="{ static: true }"
      :formList="formList"
      @findClicked="findClicked"
      @clickNumber="clickNumber"
      @clickNumber1="clickNumber1"
    />
    <div class="flex" style="width: 100%; background-color: white">
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }" style="border: 1px solid #dcdfe6">
        <h1 class="f16">新增作业</h1>
        <el-form-item label="型体" class="f14 mb5 mt5">
          <el-input v-model="addStyle" placeholder="" clearable @change="" style="width: 120px; height: 26px"></el-input>
          <el-button type="primary" size="default" class="primaryBth ml10" @click="addOne">新增</el-button>
        </el-form-item>

        <div class="flex">
          <h1 class="f16">型体</h1>
          <span style="color: #0000ff" class="f14 ml10">填充绿色为已检核</span>
        </div>
        <Table
          :outTableHeight="-200"
          :TableHeight="66"
          :tableHeader="tableHeader"
          :tableData="tableData"
          selection
          :isLoading="isLoading"
          @currentRow="currentRow"
          @sortChange="sortChange"
          @selectList="selectTable1List"
        />
        <PageModule
          :PageData="{ total, pageSizeShow: true, buttonS: true, pagerCount: 4 }"
          :layout="'prev, pager'"
          @pageSizeChange="handleSizeChange"
          @pageChange="handleCurrentChange"
        />
      </el-card>

      <el-card shadow="never" :body-style="{ padding: '0 0px 0' }" style="border: 1px solid #dcdfe6; flex: 1">
        <JFind :searchImg="false" :OriginalFilter="{ static: true }" :formList="formList9" @findClicked="findClicked9" />

        <h1 class="f16 ml10">基本资料</h1>
        <Find class="ml10" :OriginalFilter="{ static: true }" :formList="formList2" :searchImg="false" />

        <h1 class="f16 mt10 ml10">制具资料</h1>
        <div class="ml10">
          <Table :tableHeader="tableHeader2" :tableData="tableData2" :TableHeight="10" @selectListShow="selectListShowTable2" />
        </div>

        <div class="flex ml10">
          <h1 class="f16">型体配色资料</h1>
          <el-button
            style="background-color: red"
            :disabled="currentTableRow.backgroundColor === '#40FF80' ? true : false"
            class="primaryBth ml20"
            type="primary"
            size="default"
            @click="removeCurrentRow4"
            >删除当前行</el-button
          >
          <el-button
            :disabled="currentTableRow.backgroundColor === '#40FF80' ? true : false"
            class="primaryBth ml20"
            type="primary"
            size="default"
            @click="addCurrentRow4"
            >添加数据</el-button
          >
          <!-- <el-button style="background-color: brown" :disabled="currentTableRow.backgroundColor === '#40FF80' ? true : false" class="primaryBth ml20" type="primary" size="default" @click="save"
              >保存</el-button
            > -->
          <el-button
            style="background-color: #67c23a"
            :disabled="currentTableRow.backgroundColor === '#40FF80' ? true : false"
            class="primaryBth ml20"
            type="primary"
            size="default"
            @click="SetOrderNo"
            >生成订单号</el-button
          >
        </div>
        <Table
          :TableHeight="60"
          :outTableHeight="120"
          @currentRow="currentRow4"
          :tableHeader="tableHeader4"
          :tableData="tableData4"
          @successUpload="successUpload"
          @confirmChange="inputChange"
          @download="download"
          @inputChange="inputChange4"
        />
      </el-card>

      <el-dialog v-model="dialogVisible" title="制单员变更" width="30%">
        <el-select v-model="DocumentMaker" value-key="" placeholder="" clearable filterable @change="">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
        </el-select>
        <el-button class="primaryBth ml20" type="primary" size="default" @click="confirmChange('change')">确认变更</el-button>
      </el-dialog>

      <el-dialog v-model="copyVisible" title="复制型体" width="39%">
        <el-form class="flex">
          <el-form-item label="原型体">
            <el-input disabled v-model="oldStyle" placeholder="" clearable @change="" style="width: 150px; height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="新型体" class="ml20">
            <el-input v-model="newStyle" placeholder="" clearable @change="" style="width: 150px; height: 26px"></el-input>
          </el-form-item>
          <el-form-item class="ml20">
            <el-button style="" class="primaryBth" type="primary" size="default" @click="confirmChange('copy')">复制</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>

      <!-- 大图细节补充抽屉 -->
      <el-drawer v-model="drawer2" title="大图细节补充" direction="rtl" width="60%">
        <div v-for="item in bigPicArr as any">
          <div class="flex">
            <el-button style="background-color: red" type="primary" size="default" @click="removeImage(item) as any">删除图片</el-button>
            <el-input @change="changeRemark(item)" v-model="item.remark" placeholder="请输入备注" clearable></el-input>
          </div>
          <el-upload
            class="avatar-uploader"
            drag
            :action="'/kl/development/updateStylePhoto'"
            :show-file-list="false"
            :on-success="(response:any)=>handleAvatarSuccess(response,item)"
            :headers="{ Authorization: token }"
            list-type="picture"
          >
            <img v-if="item.photoPath" :src="item.photoPath" class="avatar" />
            <span v-else class="svg-container">
              <svg-icon name="ele-Plus" />
            </span>
          </el-upload>
        </div>
      </el-drawer>

      <!-- 多余数据资料抽屉 -->
      <el-drawer v-model="drawer3" title="数据资料" direction="rtl">
        <el-form ref="form" label-width="140px" :inline="false">
          <el-form-item label="护眼外量(贴底前)">
            <el-input v-model="obj.outsideTheEyes" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="后跟内量高度">
            <el-input v-model="obj.heelHeight" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="领口外内量高度">
            <el-input v-model="obj.collar1Height" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="鞋带长度">
            <el-input v-model="obj.shoelaces" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="头翘">
            <el-input v-model="obj.headLifted" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="护眼内量高度">
            <el-input v-model="obj.protectTheEyes" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="鞋头定点">
            <el-input v-model="obj.shoeToe" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="鞋舌长度">
            <el-input v-model="obj.tongueLength" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="领口内内量高度">
            <el-input v-model="obj.collar2Height" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="后套定点">
            <el-input v-model="obj.rearFixedPoint" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="后跟外量（贴底前）">
            <el-input v-model="obj.heelOutside" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">确认</el-button>
            <el-button type="primary" @click="deleteConfirm" style="background-color: red">删除</el-button>
          </el-form-item>
        </el-form>
        <div class="ml10">
          <div class="flex">
            <h1 class="f16" style="width: 100px">配码资料</h1>
            <el-button
              :disabled="currentTableRow.backgroundColor === '#40FF80' ? true : false"
              class="primaryBth ml20"
              type="primary"
              size="default"
              @click="addNumber"
              >确认</el-button
            >
            <el-button
              :disabled="currentTableRow.backgroundColor === '#40FF80' ? true : false"
              class="primaryBth ml20"
              type="primary"
              size="default"
              @click="removeCurrentRow"
              >删除当前行</el-button
            >
          </div>
          <el-select v-model="getNoList" multiple placeholder="取号码">
            <el-option
              v-for="item in shotNoSelectList.map((item: any) => {
            return {
              label: item.sizeNo,
              value: `${item.seqNo}  ${item.sizeNo}`, //中间空两个
            };
          })"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>

          <Table :tableHeader="tableHeader3" :tableData="tableData3" :TableHeight="60" :outTableHeight="120" @currentRow="currentRow3" />
        </div>
      </el-drawer>

      <!-- 生成订单号 -->
      <el-drawer v-model="drawer4" title="数据资料" direction="ttb">
        <JDialog :tableHeader="JTableHeader5" :width="73" @confirm="confirm" :unEdit="true" :unSub="true" />
        <Table
          @currentRow="currentRow5"
          @download="download2"
          :tableHeader="tableHeader5"
          :tableData="tableData5"
          class="mt10"
          :isLoading="isLoading5"
        />

        <!-- <el-form ref="form" label-width="140px" :inline="false">
          <el-form-item label="样品类型">
            <el-input v-model="sampleType" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="订单数量">
            <el-input v-model="orderQty" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="交期">
            <el-date-picker
              v-model="deliveryDate"
              type="date"
              placeholder=""
              :format="'YYYY-MM-DD'"
              :value-format="'YYYY-MM-DD'"
              style="height: 26px"
            />
          </el-form-item>
          <el-form-item label="码数">
            <el-input v-model="sizeNo" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="纸板号">
            <el-input v-model="shoeName" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="面衬">
            <el-input v-model="sockNo" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item label="BOM订单数">
            <el-input v-model="bomOrderQty" placeholder="" clearable @change="" style="height: 26px"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit2">确认</el-button>
          </el-form-item>
        </el-form> -->
      </el-drawer>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { selectList, selectSomeList } from '@/plugins/mixin'
import LoginWork from '@/utils/LoginWork'
import { formateData } from '@/plugins/mixinJ'
import router from '@/router'
import type { AxiosResponse } from 'axios'
import fileRequest from '@/utils/fileRequest'
import { Plus } from '@element-plus/icons-vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'RdTypeBodyFile1'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { computed, reactive, ref } from 'vue'
import { ElMessage, ElSwitch, genFileId, type UploadFile, type UploadFiles } from 'element-plus'
import service from '@/utils/request'
import { debounce } from 'lodash'
import { onMounted, watch } from 'vue'
const sockNo = ref('')
const currentPhotoPath = ref('')
const token = computed(() => {
  const token = sessionStorage.getItem('Authorization')
  if (token) {
    return token
  } else {
    return 'LTF_token'
  }
})

const bigPicArr = ref([
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  },
  {
    photoPath: '',
    id: '',
    remark: ''
  }
]) as any
const handleAvatarSuccess = async (response: any, item: any) => {
  if (item.id) {
    const res = (await LoginWork.post('/development/getStylePhotoUpdate2', {
      ...currentTableRow4.value,
      ...currentImgArr.value[0],
      photoPath: response.data.photoPath,
      styleNo: currentTableRow.value.styleNo,
      id: item.id,
      remark: item.remark
    })) as any
    if (res.code === 200) {
      JMessage.success('上传成功')
      getBigPic()
    } else {
      JMessage.error(res.message)
    }
  } else {
    const res = (await LoginWork.post('/development/getStylePhotoAdd2', {
      ...currentTableRow4.value,
      photoPath: response.data.photoPath,
      styleNo: currentTableRow.value.styleNo,
      id: '',
      remark: item.remark
    })) as any
    if (res.code === 200) {
      JMessage.success('上传成功')
      getBigPic()
    } else {
      JMessage.error(res.message)
    }
  }
}
const removeImage = async (item: any) => {
  const res = (await LoginWork.post(`/development/getStylePhotoDelete`, item)) as any
  if (res.code === 200) {
    JMessage.success('删除成功')
    item.photoPath = ''
    item.id = ''
    item.remark = ''
  } else {
    JMessage.error(res.message)
  }
}
const currentImgArr = ref([{}, {}])
const getBigPic = async () => {
  bigPicArr.value.forEach((item: any) => {
    item.photoPath = ''
    item.id = ''
    item.remark = ''
  })
  const res = (await LoginWork.post(
    `/development/getStylePhoto?style=${currentTableRow.value.styleNo}&styleColor=${currentTableRow4.value.styleColor}`
  )) as any
  res.data.forEach((item: any, index: number) => {
    bigPicArr.value[index].photoPath = item.photoPath
    bigPicArr.value[index].id = item.id
    bigPicArr.value[index].remark = item.remark
  })
}
const drawer4 = ref(false)
const sampleType = ref('')
const orderQty = ref('')
const deliveryDate = ref('')
const sizeNo = ref('')
const shoeName = ref('')
const bomOrderQty = ref('')
const onSubmit = async () => {
  if (obj.value.id === '') {
    const res = (await LoginWork.post(`/development/getStyleProcessDataAdd`, {
      ...obj.value,
      styleNo: currentTableRow5.value.orderId
    })) as any
    if (res.code === 200) {
      JMessage.success('添加成功')
      currentRow(currentTableRow.value)
      download2(currentTableRow5.value)
    } else {
      JMessage.warning(res.message)
    }
  } else {
    const res = (await LoginWork.post(`/development/getStyleProcessDataUpdate`, obj.value)) as any
    if (res.code === 200) {
      JMessage.success('修改成功')
      currentRow(currentTableRow.value)
      download2(currentTableRow5.value)
    } else {
      JMessage.warning(res.message)
    }
  }
}

// Dialog确认添加/修改按钮
const confirm = async (obj: any, dialogVisible: any, title: any) => {
  // 向服务器发送请求，更新外派单信息
  if (title === '添加') {
    console.log(obj)
    const res = (await LoginWork.post(`/pcOrder/setSampleTypeWithGeneration`, {
      color: currentTableRow4.value.styleColor,
      style: currentTableRow.value.styleNo,
      ...obj
    })) as any
    // 判断请求是否成功
    if (res.code === 200) {
      JMessage.success(res.message)
      save()
      // 关闭弹出框
      dialogVisible.value = false
      // drawer4.value = false
    } else {
      JMessage.error(res.message)
    }
  }

  // 重新获取表格数据
  getTableList5()
}
const onSubmit2 = async () => {
  const res = (await LoginWork.post('/pcOrder/setSampleTypeWithGeneration', {
    color: currentTableRow4.value.styleColor,
    style: currentTableRow.value.styleNo,
    sampleType: sampleType.value,
    orderQty: orderQty.value,
    deliveryDate: deliveryDate.value,
    sizeNo: sizeNo.value,
    sockNo: sockNo.value,
    shoeName: shoeName.value,
    bomQty: bomOrderQty.value
  })) as any
  if (res.code === 200) {
    JMessage.success('生成订单号成功')
    save()
    drawer4.value = false
  } else {
    JMessage.error(res.message)
  }
}

const drawer3 = ref(false)
const addStyle = ref('')
const dialogVisible = ref(false)
const copyVisible = ref(false)
const DocumentMaker = ref('')
const oldStyle = ref('')
const newStyle = ref('')
const options = ref([{ value: '', label: '' }])
const drawer = ref(false)
const getNoList = ref([]) as any
const currentTableRow4 = ref({}) as any
const currentStyleColor = ref('') as any
const currentRow4 = async (row: any = tableData4.value[0]) => {
  currentTableRow4.value = row
  currentStyleColor.value = row.styleColor
}
// 表二下拉列表触发函数
const shotNoSelectList = ref([
  {
    value: '',
    label: ''
  }
]) as any
// 下拉框数据获取
const sizeList = ref<any>([])
const getSelectList = async () => {
  sizeList.value = await service.get('/back/getSizeTypeByName')

  await selectList(formList2, () => service.get('/back/order/allOrderCondition'))
  await selectSomeList(formList, () => service.get('/back/getChangeOfOrderMakerList'))
  sizeList.value.forEach((item: any, index: number) => {
    formList2.value
      .find((item2: any) => item2.selectP && Jzhcn.Find[item2.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '码制')
      .selectOptions.push({
        optionKey: index,
        optionLabel: item.sizeNotice,
        optionValue: `${item.sizeCode}  ${item.sizeNotice}`
      })
  })
  const res = await service.get<any, any>('/back/getChangeOfOrderMakerList')
  if (res) {
    res.forEach((item: any, index: any) => {
      if (item === null) return
      options.value.push({
        value: item,
        label: item
      })
    })
  }
}
onMounted(() => {
  getSelectList()
})
// 制单员变更里面的按钮点击事件
const confirmChange = async (type: string) => {
  if (type === 'change') {
    const res = await LoginWork.post<any, any>('/development/getChangeOfOrderMaker', {
      styleNo: currentTableRow.value.styleNo,
      techPerson: DocumentMaker.value
    })
    if (res.code === 200) {
      JMessage.success('变更成功')
      dialogVisible.value = false
      getTableList()
    } else {
      JMessage.warning(res.message)
    }
  } else if (type === 'copy') {
    //配码资料集合
    const numberList = formateData(tableData3.value).map((item: any) => {
      if (item.sizeNo.indexOf('  ') !== -1) {
        item.seqNo = item.sizeNo.split('  ')[0]
        item.sizeNo = item.sizeNo.split('  ')[1]
      }
      return item
    })
    //制具资料集合
    const typeList = formateData(tableData2.value).map((item: any) => {
      if (item.size1 && item.size1.indexOf('  ') !== -1) {
        item.seqNo1 = item.size1.split('  ')[0]
        item.size1 = item.size1.split('  ')[1]
      }
      if (item.size2 && item.size2.indexOf('  ') !== -1) {
        item.seqNo2 = item.size2.split('  ')[0]
        item.size2 = item.size2.split('  ')[1]
      }
      return item
    })
    console.log(numberList)

    const res = await LoginWork.post<any, any>('/development/getStyleBasicCopyAdd', {
      styleName: formList2.value[0].inputValue, // 鞋名
      sizeType: formList2.value[1].selectValue.indexOf('  ') == -1 ? formList2.value[1].selectValue : formList2.value[1].selectValue.split('  ')[1],
      baseSize: formList2.value[2].inputValue, // 基本号(鞋号)
      custNo: formList2.value[3].inputValue, // 客户
      custStyle: formList2.value[4].inputValue, // 客户型体
      shoeType: formList2.value[5].inputValue, // 鞋款分类
      shoeSex: formList2.value[6].inputValue, // 鞋款性别
      custBrand: formList2.value[7].inputValue, // 商标
      prevCustStyle: formList2.value[8].inputValue, // 原客户型体
      soleVendor: formList2.value[9].inputValue, // 	大底厂商
      soleMtl: formList2.value[10].inputValue, // 大底类别
      numberList, //配码资料集合
      photoList: null, //型体配色资料集合
      styleNo: newStyle.value, //型体
      typeList: typeList[0] //制具资料集合
    })
    if (res.code === 200) {
      JMessage.success('复制成功')
      getTableList()
      currentRow(currentTableRow.value)
      copyVisible.value = false
    } else {
      JMessage.warning(res.message)
    }
  }
}
// 新增作业
const addOne = async () => {
  const res = (await LoginWork.post('/development/getStyleAdd', {
    styleNo: addStyle.value
  })) as any
  if (res.code === 200) {
    JMessage.success('新增成功')
    getTableList()
    addStyle.value = ''
  } else {
    JMessage.error(res.message)
  }
}
// Find中单选框
const radio = ref('0')
const clickNumber = (row: any) => {
  radio.value = row
  getTableList()
}
const clickNumber1 = (row: any) => {
  radio.value = row
  getTableList()
}

// 表一模块
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '制单员',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入鞋名',
    inputValue: ''
  },
  // {
  //   type: 'input',
  //   inputPlaceholder: '请输入冲刀',
  //   inputValue: ''
  // },
  {
    type: 'radio1',
    checkboxLabel: '我的型体',
    label: ''
  },
  {
    type: 'radio1',
    checkboxLabel: '所有型体',
    label: '0'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])
const formList9 = ref([
  {
    type: 'button',
    checkboxLabel: '保存',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '复制'
  },
  {
    type: 'button',
    checkboxLabel: '整单删除'
  },
  {
    type: 'button',
    checkboxLabel: '制单员变更'
  },
  {
    type: 'button',
    checkboxLabel: '打勾检核',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '取消检核',
    bgColor: '#1890FF'
  },
  // {
  //   type: 'button',
  //   checkboxLabel: '转型体配色BOM建档'
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '转指令资料输入'
  // },
  {
    type: 'button',
    checkboxLabel: '大图细节补充',
    bgColor: '#67C23A'
  }
  // {
  //   type: 'button',
  //   checkboxLabel: '数据资料',
  //   bgColor: '#67C23A'
  // }
])
const imgList = ref([])
const currentTableRow = ref({}) as any
const currentSizeCode = ref('01')
const tableHeader = ref([
  {
    sortable: 'custom',
    label: '型体',
    prop: 'styleNo',
    backgroundColor: true
  },
  {
    label: '制单员',
    prop: 'techPerson',
    width: 70
  }
])
const selectedLists = ref([])
const selectTable1List = (selectedList: any) => {
  selectedLists.value = selectedList
}
const drawer2 = ref(false)
const fileList = ref<any[]>([])
const dialogImageUrl2 = ref('')
const dialogVisible2 = ref(false)
const handlePictureCardPreview: any['onPreview'] = (uploadFile: any) => {
  dialogImageUrl2.value = uploadFile.url!
  dialogVisible2.value = true
}
const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
}
const findClicked9 = async (content: string) => {
  const styleNoList = selectedLists.value.map((item: any) => {
    return item.styleNo
  })
  // 如果检核了，就不能再检核
  const reg = selectedLists.value.some((item: any) => item.backgroundColor !== null)
  const reg2 = selectedLists.value.some((item: any) => item.backgroundColor === null)

  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '保存') {
    save()
  }
  if (content === '复制') {
    copyVisible.value = true
  }
  if (content === '整单删除') {
    if (currentTableRow.value.backgroundColor === '#40FF80') {
      JMessage.warning('已检核不能删除')
      return
    }
    const res = (await LoginWork.post('/development/getStyleBasicAllDel', {
      styleNo: currentTableRow.value.styleNo
    })) as any
    if (res.code === 200) {
      JMessage.success('删除成功')
    } else {
      JMessage.error(res.message)
    }
    getTableList()
    formList2.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '制单员变更') {
    dialogVisible.value = true
  }
  if (content === '打勾检核') {
    if (!reg) {
      const res = (await LoginWork.post('/development/getInspect/0', styleNoList)) as any
      if (res.code === 200) {
        JMessage.success('检核成功')
        getTableList()
      } else {
        JMessage.warning('检核失败')
      }
    } else {
      JMessage.warning('已检核的不能再检核')
    }
  }
  if (content === '取消检核') {
    if (!reg2) {
      const res = (await LoginWork.post('/development/getInspect/1', styleNoList)) as any
      if (res.code === 200) {
        JMessage.success('取消检核成功')
        getTableList()
      } else {
        JMessage.success('取消检核失败')
      }
    } else {
      JMessage.warning('取消检核的不能再取消检核')
    }
  }
  if (content === '转型体配色BOM建档') {
    router.push('/ControlDepartment/MaterialManagement/ResearchAndDevelopmentVolumeDocumentation')
  }
  if (content === '转指令资料输入') {
    router.push('/ControlDepartment/MaterialManagement/ResearchAndDevelopmentVolumeDocumentation')
  }
  if (content === '大图细节补充') {
    drawer2.value = true
    getBigPic()
  }
  if (content === '数据资料') {
    drawer3.value = true
  }
}

const save = async (silence = false) => {
  //配码资料集合
  const numberList = formateData(tableData3.value).map((item: any) => {
    if (item.sizeNo.indexOf('  ') !== -1) {
      item.seqNo = item.sizeNo.split('  ')[0]
      item.sizeNo = item.sizeNo.split('  ')[1]
    }
    return item
  })
  //制具资料集合
  const typeList = formateData(tableData2.value).map((item: any) => {
    if (item.size1 && item.size2 && item.size1.selectValue === '' && item.size2.selectValue === '') {
      item.size1 = ''
      item.size2 = ''
    }
    if (item.size1 && item.size1.indexOf('  ') !== -1) {
      item.seqNo1 = item.size1.split('  ')[0]
      item.size1 = item.size1.split('  ')[1]
    }
    if (item.size2 && item.size2.indexOf('  ') !== -1) {
      item.seqNo2 = item.size2.split('  ')[0]
      item.size2 = item.size2.split('  ')[1]
    }
    return item
  })
  if (!formList2.value[1].selectValue) {
    JMessage.error('请选择码制')
    return
  }
  const res = await LoginWork.post<any, any>('/development/getStyleBasicAdd', {
    styleName: formList2.value[0].inputValue, // 鞋名
    sizeType: formList2.value[1].selectValue.indexOf('  ') == -1 ? formList2.value[1].selectValue : formList2.value[1].selectValue.split('  ')[1],
    baseSize: formList2.value[2].inputValue, // 基本号(鞋号)
    custNo: formList2.value[3].inputValue, // 客户
    custStyle: formList2.value[4].inputValue, // 客户型体
    shoeType: formList2.value[5].inputValue, // 鞋款分类
    shoeSex: formList2.value[6].inputValue, // 鞋款性别
    custBrand: formList2.value[7].inputValue, // 商标
    prevCustStyle: formList2.value[8].inputValue, // 原客户型体
    soleVendor: formList2.value[9].inputValue, // 	大底厂商
    soleMtl: formList2.value[10].inputValue, // 大底类别
    numberList, //配码资料集合
    photoList: tableData4.value, //型体配色资料集合
    styleNo: currentTableRow.value.styleNo, //型体
    typeList: typeList[0] //制具资料集合
  })
  if (res.code === 200) {
    JMessage.success('保存成功')
    if (!silence) getTableList()
  } else {
    JMessage.warning(res.message)
  }
}
const tableData = ref([])
const isLoading = ref(true)
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
// 获取表数据
const getTableList = debounce(async () => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/development/getStyleBasicList', {
    // cutTool: formList.value.find((item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入冲刀')?.inputValue,
    season: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度')
      ?.selectValue,
    sort: order.value,
    styleName: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入鞋名'
    )?.inputValue,
    styleNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
    )?.inputValue,
    techPerson: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '制单员')
      ?.selectValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value,
    num: radio.value === '0' ? '' : '0'
  })
  isLoading.value = false
  tableData.value = tableDataList.list.map((item: any) => {
    item.disableConfirm = true
    return item
  })
  total.value = tableDataList.total
  oldStyle.value = tableDataList.list[0].styleNo

  currentRow()
}, 500)
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)
// 表格排序
const order = ref('0')
const sortChange = (sort: any, prop: any, column: any) => {
  if (sort === 'ascending') {
    order.value = '1'
  } else if (sort === 'descending') {
    order.value = '2'
  } else {
    order.value = '0'
  }
  getTableList()
}
// 点击表给另一张表传数据
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}) => {
  currentTableRow.value = row
  oldStyle.value = row.styleNo

  await getFindData()

  await getTableList2()

  await getSelectData()

  await getTableList3()

  await getTableList4()
}
const obj = ref({
  id: '',
  outsideTheEyes: '',
  heelHeight: '',
  collar1Height: '',
  shoelaces: '',
  headLifted: '',
  protectTheEyes: '',
  shoeToe: '',
  tongueLength: '',
  collar2Height: '',
  rearFixedPoint: '',
  heelOutside: '',
  styleNo: ''
}) as any

const addZD = async () => {
  obj.value.styleNo = currentTableRow.value.styleNo
  if (obj.value.id === '') {
    const res = (await LoginWork.post(`/development/getStyleProcessDataAdd`, {
      ...obj.value,
      styleNo: currentTableRow5.value.orderId
    })) as any
    if (res.code === 200) {
      JMessage.success('保存成功')
      currentRow(currentTableRow.value)
    } else {
      JMessage.warning(res.message)
    }
  } else {
    const res = (await LoginWork.post(`/development/getStyleProcessDataUpdate`, obj.value)) as any
    if (res.code === 200) {
      JMessage.success('保存成功')
      currentRow(currentTableRow.value)
    } else {
      JMessage.warning(res.message)
    }
  }
}
const deleteConfirm = async () => {
  console.log(obj.value)
  if (obj.value.id === '') {
    JMessage.warning('还没新建数据')
    return
  }
  const res = (await LoginWork.post(`/development/getStyleProcessDataDel`, obj.value)) as any
  if (res.code === 200) {
    JMessage.success('删除成功')
    currentRow(currentTableRow.value)
    download2(currentTableRow5.value)
  } else {
    JMessage.warning(res.message)
  }
}

// 基本资料
const formList2 = ref<any>([
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '鞋名',
    inputValue: ''
  },
  // {
  //   type: 'select',
  //   selectValue: '',
  //   selectP: '鞋名',
  //   selectOptions: [
  //     {
  //       optionKey: '',
  //       optionLabel: ' ',
  //       optionValue: ' '
  //     }
  //   ]
  // },
  {
    type: 'select',
    selectValue: '',
    selectP: '码制',
    selectOptions: [
      {
        optionKey: '',
        optionLabel: ' ',
        optionValue: ' '
      }
    ]
  },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '基本号(鞋号)',
    inputValue: ''
  },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '客户',
    inputValue: ''
  },
  // {
  //   type: 'select',
  //   selectValue: '',
  //   selectP: '客户',
  //   selectOptions: [
  //     {
  //       optionKey: '',
  //       optionLabel: ' ',
  //       optionValue: ' '
  //     }
  //   ]
  // },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '客户型体',
    inputValue: ''
  },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '鞋款分类',
    inputValue: ''
  },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '鞋款性别',
    inputValue: ''
  },
  // {
  //   type: 'select',
  //   selectValue: '',
  //   selectP: '鞋款性别',
  //   selectOptions: [
  //     {
  //       optionKey: '1',
  //       optionLabel: '男鞋',
  //       optionValue: '男鞋'
  //     },
  //     {
  //       optionKey: '2',
  //       optionLabel: '女鞋',
  //       optionValue: '女鞋'
  //     }
  //   ]
  // },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '商标',
    inputValue: ''
  },
  // {
  //   type: 'select',
  //   selectValue: '',
  //   selectP: '商标',
  //   selectOptions: [
  //     {
  //       optionKey: '',
  //       optionLabel: ' ',
  //       optionValue: ' '
  //     }
  //   ]
  // },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '原客户型体',
    inputValue: ''
  },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '大底厂商',
    inputValue: ''
  },
  // {
  //   type: 'select',
  //   selectValue: '',
  //   selectP: '大底厂商',
  //   selectOptions: [
  //     {
  //       optionKey: '',
  //       optionLabel: ' ',
  //       optionValue: ' '
  //     }
  //   ]
  // },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '大底类别',
    inputValue: ''
  },
  // {
  //   type: 'input',
  //   inputLabel: '',
  //   inputPlaceholder: '样品阶段',
  //   inputValue: ''
  // },
  // {
  //   type: 'dateSingle',
  //   placeholder: '下单日期',
  //   dateValue: ''
  // },
  // {
  //   type: 'dateSingle',
  //   placeholder: '样品交期',
  //   dateValue: ''
  // },
  // {
  //   type: 'input',
  //   inputLabel: '',
  //   inputPlaceholder: '数量',
  //   inputValue: ''
  // },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '版师负责人',
    inputValue: ''
  },
  {
    type: 'input',
    inputLabel: '',
    inputPlaceholder: '版次',
    inputValue: ''
  }
  // {
  //   type: 'select',
  //   selectValue: '',
  //   selectP: '大底类别',
  //   selectOptions: [
  //     {
  //       optionKey: '',
  //       optionLabel: ' ',
  //       optionValue: ' '
  //     }
  //   ]
  // }
])
const getFindData = () => {
  // 判断检核
  if (currentTableRow.value.backgroundColor === '#40FF80') {
    formList2.value.forEach((item: any) => {
      item.disabled = true
      item.inputDisabled = true
    })
  } else {
    formList2.value.forEach((item: any) => {
      item.disabled = false
      item.inputDisabled = false
    })
  }
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '鞋名'
  ).inputValue = currentTableRow.value.styleName
  formList2.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '码制').selectValue =
    currentTableRow.value.sizeType
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '基本号(鞋号)'
  ).inputValue = currentTableRow.value.baseSize
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '客户'
  ).inputValue = currentTableRow.value.custNo
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '客户型体'
  ).inputValue = currentTableRow.value.custStyle
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '鞋款分类'
  ).inputValue = currentTableRow.value.shoeType
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '鞋款性别'
  ).inputValue = currentTableRow.value.shoeSex
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '商标'
  ).inputValue = currentTableRow.value.custBrand
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '原客户型体'
  ).inputValue = currentTableRow.value.prevCustStyle
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '大底厂商'
  ).inputValue = currentTableRow.value.soleVendor
  formList2.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '大底类别'
  ).inputValue = currentTableRow.value.soleMtl
}
// 获取取号码下拉框数据
const getSelectData = async () => {
  // 筛选得到sizeCode码制
  if (currentTableRow.value.sizeType)
    currentSizeCode.value = sizeList.value.find((item: any) => item.sizeNotice === currentTableRow.value.sizeType).sizeCode
  if (shotNoSelectList.value.length) shotNoSelectList.value.splice(0)
  if (currentTableRow.value.sizeType) {
    shotNoSelectList.value = await service.post<any, any>('/development/getStyleNumber', {
      sizeType: currentTableRow.value.sizeType,
      sizeCode: currentSizeCode.value
    })
  }

  // 获取样品类型下拉框
  const res = (await LoginWork.get('/pcOrder/getSampleType')) as any
  if (res.code === 200) {
    JTableHeader5.find((item: any) => item.label === '样品类型').options = []
    JTableHeader5.find((item: any) => item.label === '样品类型').options = res.data.map((item: any) => {
      return { value: item, label: item }
    })
    console.log(
      res.data.map((item: any) => {
        return { value: item.value, label: item.label }
      })
    )
  } else {
    JMessage.error(res.message)
  }
}
// 改变码制获取下拉框数据
watch(
  () => formList2.value[1].selectValue,
  async (newValue, oldValue) => {
    // console.log(newValue);
    if (newValue !== null && newValue !== undefined && newValue.indexOf('  ') !== -1) {
      // 获取下拉数据
      shotNoSelectList.value = await service.post<any, any>('/development/getStyleNumber', {
        sizeType: newValue.split('  ')[1],
        sizeCode: newValue.split('  ')[0]
      })
      tableData2.value.forEach((item: any) => {
        item.size1 = {
          selectValue: '',
          options: shotNoSelectList.value.map((item: any) => {
            return {
              label: item.sizeNo,
              value: `${item.seqNo}  ${item.sizeNo}` //中间空两个
            }
          })
        }
        item.size2 = {
          selectValue: '',
          options: shotNoSelectList.value.map((item: any) => {
            return {
              label: item.sizeNo,
              value: `${item.seqNo}  ${item.sizeNo}` //中间空两个
            }
          })
        }
      })
    }
  },
  { deep: true }
)

// 表二模块
const tableData2 = ref<any>([])
const tableHeader2 = ref([
  {
    change: true,
    label: '序号',
    prop: 'typeNo'
  },
  {
    label: '楦头编号',
    prop: 'lastMold'
  },
  {
    label: '大底编号',
    prop: 'solePart'
  },
  {
    label: '冲刀编号',
    prop: 'cutTool'
  },
  {
    label: '中底编号',
    prop: 'midsole'
  },
  {
    label: '鞋垫编号',
    prop: 'insole'
  }
  // {
  //   disable: true,
  //   type: 'select',
  //   label: '段',
  //   prop: 'itemName'
  // },
  // {
  //   disable: true,
  //   type: 'select',
  //   label: '鞋码起',
  //   prop: 'size1'
  // },
  // {
  //   disable: true,
  //   type: 'select',
  //   label: '鞋码止',
  //   prop: 'size2'
  // }
])
const getTableList2 = async () => {
  // 制具资料
  let res = (await service.get<any, any>(`/development/getStyleType?styleNo=${currentTableRow.value.styleNo}`)) as any
  if (res === null) {
    res = {
      typeNo: '1',
      lastMold: '',
      solePart: '',
      cutTool: '',
      midsole: '',
      insole: '',
      size1: { selectValue: '', options: [] },
      size2: { selectValue: '', options: [] },
      itemName: {
        selectValue: '',
        options: [
          {
            label: '童段楦头',
            value: '童段楦头' //中间空两个
          },
          {
            label: '女段楦头',
            value: '女段楦头' //中间空两个
          },
          {
            label: '男段楦头',
            value: '男段楦头' //中间空两个
          }
        ]
      },
      change: 'Y',
      disableConfirm: true
    }
  } else if (currentTableRow.value.backgroundColor !== '#40FF80') {
    res.itemName = {
      selectValue: res.itemName,
      options: [
        {
          label: '童段楦头',
          value: '童段楦头' //中间空两个
        },
        {
          label: '女段楦头',
          value: '女段楦头' //中间空两个
        },
        {
          label: '男段楦头',
          value: '男段楦头' //中间空两个
        }
      ]
    }
    res.size1 = { selectValue: res.size1, options: [] }
    res.size2 = { selectValue: res.size2, options: [] }
    res.change = 'Y'
    res.disableConfirm = true
  } else {
    res.itemName = {
      selectValue: res.itemName,
      options: []
    }
    res.size1 = { selectValue: res.size1, options: [] }
    res.size2 = { selectValue: res.size2, options: [] }
    res.disable = true // 下拉框禁用
  }
  tableData2.value = [res]
}

const selectListShowTable2 = (row: any) => {
  row.size1.options = []
  row.size2.options = []
  shotNoSelectList.value.forEach((item: any) => {
    row.size1.options.push({ label: item.sizeNo, value: `${item.seqNo}  ${item.sizeNo}` })
    row.size2.options.push({ label: item.sizeNo, value: `${item.seqNo}  ${item.sizeNo}` })
  })
}

// 表三模块
const tableHeader3 = ref([
  {
    label: '鞋码',
    prop: 'sizeNo'
  },
  {
    label: '冲刀',
    prop: 'cutSize'
  },
  {
    label: '楦头',
    prop: 'lastSize'
  },
  {
    label: '大底',
    prop: 'soleSize'
  },
  {
    label: '中底',
    prop: 'insoleSize'
  },
  {
    label: '鞋垫/脚床',
    prop: 'midsoleSize'
  }
])
const tableData3 = ref<any>([])
const getTableList3 = async () => {
  const res = await service.post<any, any>(`/development/getStyleSizeList`, {
    styleNo: currentTableRow.value.styleNo,
    typeNo: '1'
  })
  if (res.length === 0)
    tableData3.value = res.map((item: any) => {
      // 判断检核
      if (currentTableRow.value.backgroundColor !== '#40FF80') item.change = 'Y'
      item.disableConfirm = true
      return item
    })
  getNoList.value = []
  // changeNoList(getNoList)

  tableData3.value.forEach((item2: any) => {
    shotNoSelectList.value.forEach((item: any, index: number) => {
      if (item2.sizeNo === item.sizeNo) {
        getNoList.value.push(item.seqNo + '  ' + item.sizeNo)
      }
    })
  })
}

// 点击表给另一张表传数据
const currentTableRow3 = ref({}) as any
const currentRow3 = async (row: any = tableData3.value[0]) => {
  currentTableRow3.value = row
}
// 点击取号码触发函数
const addNumber = async () => {
  console.log(shotNoSelectList.value, getNoList.value)
  const res = await LoginWork.post<any, any>('/development/getStyleNumberAdd', {
    numberList: getNoList.value.map((item: any) => {
      return {
        seqNo: item.split('  ')[0],
        sizeNo: item.split('  ')[1],
        cutSize: item.split('  ')[1],
        lastSize: item.split('  ')[1],
        soleSize: item.split('  ')[1],
        insoleSize: item.split('  ')[1],
        midsoleSize: item.split('  ')[1]
      }
    }),
    styleNo: currentTableRow.value.styleNo,
    typeNo: '1'
  })
  JMessage.success('插入号码成功')
  getNoList.value = []
  getTableList3()
}
const removeCurrentRow = () => {
  const index = tableData3.value.indexOf(currentTableRow3.value)
  tableData3.value.splice(index, 1)
}

// 表四模块
const tableHeader4 = ref([
  {
    width: 50,
    label: '序号',
    prop: 'seqNo'
  },
  {
    label: '颜色名称',
    prop: 'styleColor'
  },
  {
    width: 80,
    label: '颜色代号',
    prop: 'colorCode'
  },
  {
    width: 80,
    label: '季度',
    prop: 'season'
  },

  {
    label: '颜色名称(英)',
    prop: 'engStyleColor'
  },
  // {
  //   label: '颜色简称',
  //   prop: 'shortStyleColor'
  // },
  {
    width: 140,
    type: 'img',
    label: '图片',
    fixed: true,
    prop: 'photoPath',
    srcList: imgList
  },
  {
    disable: true,
    type: 'upload',
    label: '上传图片',
    imgAction: '/kl/development/updateStylePhoto',
    imgData: false
  },
  {
    width: 100,
    type: 'download',
    label: '下载图片'
  }
])

const tableData4 = ref<any>([])
const getTableList4 = async () => {
  let res = (await service.post('/development/getStylePhotoList', {
    styleNo: currentTableRow.value.styleNo
  })) as any
  if (res !== null)
    tableData4.value = res.map((item: any) => {
      if (currentTableRow.value.backgroundColor !== '#40FF80') item.change = 'Y'
      item.disableConfirm = true
      return item
    })
  imgList.value = res.map((item: any) => {
    return item.photoPath
  })

  if (currentTableRow.value.backgroundColor !== '#40FF80' && tableData4.value.length === 0) {
    // for (let index = 0; index < 4; index++) {
    tableData4.value.push({
      seqNo: 1,
      change: 'Y',
      disableConfirm: true
    })
    // }
  }
  currentRow4()
}
// 上传成功函数
const successUpload = (res: any, row: any) => {
  row.photoPath = res.photoPath
  imgList.value = tableData4.value.map((item: any) => {
    return item.photoPath
  })
}
// 表四修改后触发函数
const inputChange = (row: any) => {
  let num = 0
  const index = tableData4.value.indexOf(row)
  tableData4.value.forEach((item: any) => {
    if (item.styleColor === row.styleColor) num++
  })
  if (num > 1) {
    tableData4.value.splice(index, 1)
    JMessage.warning('颜色名称不能重复')
  }
  if (row.styleColor === '') {
    tableData4.value.splice(index, 1)
    JMessage.warning('颜色名称不能为空')
  }
}
// 图片下载
const download = async (row: any) => {
  // await service.get('/development/download',{
  //   responseType:
  // })
  fetch(row.photoPath)
    // 获取 blob 对象
    .then((res) => res.blob())
    .then((blob) => {
      // 创建a标签
      var link = document.createElement('a')
      // 设置a标签为不可见
      link.style.display = 'none'
      // 将a标签添加到body
      document.body.appendChild(link)
      // 生成Blob URL并设置给a标签的href属性
      var url = window.URL.createObjectURL(blob)
      link.href = url
      // 设置a标签的download
      link.download = '图片.jpg'
      // 模拟点击事件进行下载
      link.click()
      //下载完成后清理URL对象和a标签
      window.URL.revokeObjectURL(url)
      document.body.removeChild(link)
    })
}

// 型体配色删除
const removeCurrentRow4 = async () => {
  // const res = (await LoginWork.post('/development/getStylePhotoDel', {
  //   ...currentTableRow4.value,
  //   styleNo: currentTableRow.value.styleNo
  // })) as any
  // if (res.code == 200) {
  //   JMessage.success('删除成功')
  //   getTableList4()
  // } else {
  //   JMessage.error(res.message)
  // }
  const index = tableData4.value.indexOf(currentTableRow4.value)
  tableData4.value.splice(index, 1)
  save()
}
const addCurrentRow4 = async () => {
  tableData4.value.unshift({
    change: 'Y',
    disableConfirm: true,
    photoPath: '',
    seqNo: tableData4.value.length + 1
  })
}
const inputChange4 = async (row: any) => {
  if (currentStyleColor.value === currentTableRow4.value.styleColor) currentStyleColor.value = ''
  const res = (await LoginWork.post(
    `/development/getStylePhotoUpdate?styleNo=${currentTableRow.value.styleNo}&styleColor=${currentStyleColor.value}`,
    {
      ...currentTableRow4.value,
      styleNo: currentTableRow.value.styleNo
    }
  )) as any
  if (res.code === 200) {
    JMessage.success('修改成功')
  } else {
    JMessage.error(res.message)
    getTableList4()
  }
}
const SetOrderNo = async () => {
  drawer4.value = true
  save(true)
  getTableList5()
}
const tableHeader5 = ref([
  {
    label: '订单号',
    prop: 'orderId'
  },
  {
    label: '样品类型',
    prop: 'sampleType'
  },
  {
    label: '订单数量',
    prop: 'orderQty'
  },
  {
    type: 'dateSingle2',
    label: '交期',
    prop: 'deliveryDate'
  },
  {
    label: '码数',
    prop: 'sizeNo'
  },
  {
    label: '纸板号',
    prop: 'shoeName'
  },
  {
    label: '面衬',
    prop: 'sockNo'
  },
  {
    label: 'BOM订单数',
    prop: 'bomQty'
  },
  {
    type: 'function',
    label: '功能列',
    prop: [{ label: '数据资料' }]
  }
])
const JTableHeader5 = [
  {
    label: '样品类型',
    prop: 'sampleType',
    type: 'selectJV2',
    options: []
  },
  {
    label: '订单数量',
    prop: 'orderQty'
  },
  {
    type: 'dateSingle2',
    label: '交期',
    prop: 'deliveryDate'
  },
  {
    label: '码数',
    prop: 'sizeNo'
  },
  {
    label: '纸板号',
    prop: 'shoeName'
  },
  {
    label: '面衬',
    prop: 'sockNo'
  },
  {
    label: 'BOM订单数',
    prop: 'bomQty'
  }
] as any
const isLoading5 = ref(false)
const tableData5 = ref<any>([])
const getTableList5 = async () => {
  isLoading5.value = true
  const res = (await LoginWork.post('/pcOrder/getBomByStyleColor', {
    ...currentTableRow4.value,
    color: currentTableRow4.value.styleColor,
    style: currentTableRow.value.styleNo
  })) as any
  if (res.code === 200) {
    tableData5.value = res.data
    currentRow5()
  } else {
    JMessage.error(res.message)
  }
  isLoading5.value = false
}

// 大图细节补充修改
const changeRemark = async (row: any) => {
  if (!row.id) return
  const res = (await LoginWork.post('/development/getStylePhotoUpdate2', {
    ...row,
    styleNo: currentTableRow.value.styleNo,
    styleColor: currentTableRow4.value.styleColor
  })) as any
  if (res.code === 200) {
    JMessage.success('修改成功')
  } else {
    JMessage.error(res.message)
  }
}

const currentTableRow5 = ref()
const currentRow5 = async (row: any = tableData5.value[0]) => {
  currentTableRow5.value = row
}
const download2 = async (row: any) => {
  drawer3.value = true
  const res = (await LoginWork.post(`/development/getStyleProcessData?style=${row.orderId}`)) as any

  if (res.code === 200 && res.data) {
    obj.value = res.data
  } else if (res.data === null) {
    for (const key in obj.value) {
      obj.value[key] = ''
    }
  } else {
    JMessage.warning(res.message)
  }
}
</script>

<style lang="less" scoped>
:deep(.ttb) {
  height: 83% !important;
  .el-drawer__header {
    margin: 0;
  }
}
:deep(.avatar-uploader) {
  width: 100%;
}
:deep(.svg-container) {
  width: 100%;
  height: 100%;
}

:deep(.el-upload) {
  width: 100%;
  height: 100%;
  .el-upload-dragger {
    padding: 0;
    width: 100%;
    height: 100%;
  }
}
.avatar-uploader {
  height: 300px;
  background-color: white;
  display: flex;
  justify-content: center;
  align-items: center;
}

.avatar-uploader .el-upload {
  height: 300px;
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}
.avatar {
  width: 100%;
  height: 100%;
}

:deep(.el-form-item:nth-child(1)) {
  .el-select {
    width: 200px !important;
    height: 28px;
  }
}

:deep(.disable) {
  width: 180px !important;
  height: 32px !important;

  :deep(.el-input__inner) {
    color: #191919 !important;
    font-size: 14px;
  }
}
:deep(.imgDiv) {
  width: 100%;
  background-color: white;
  height: 85% !important;
  // .img {
  //   width: 70px;
  //   height: 26px;
  // }
}
</style>

<style>
.app-main {
  background-color: white !important;
}
</style>
